package com.dxy.yesas2020goals.study.partone.disignpattern.compositepattern.safe;

import java.util.ArrayList;
import java.util.List;

public class Trunk extends Tree {
    private List<Tree> trees;

    private Integer level;

    public Trunk(String name,Integer level) {
        super(name);
        this.level = level;
        this.trees = new ArrayList<Tree>();
    }

    @Override
    public void show() {
        System.out.println(this.name);
        for (Tree tree : this.trees) {
            //控制显示格式
            if(this.level != null){
                for(int  i = 0; i < this.level; i ++){
                    //打印空格控制格式
                    System.out.print("  ");
                }
                for(int  i = 0; i < this.level; i ++){
                    //每一行开始打印一个+号
                    if(i == 0){ System.out.print("+"); }
                    System.out.print("-");
                }
            }
            //打印名称
          tree.show();
        }
    }

    public boolean add(Tree tree) {
        return this.trees.add(tree);
    }


}